package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Article struct {
	Title   string `json:"title"`
	Content string `json:"content"`
}

func main() {
	r := gin.Default()

	r.GET("/", func(c *gin.Context) {
		c.String(200, "值：%v", "首页")
	})

	r.GET("/json", func(c *gin.Context) {
		article := &Article{
			Title:   "侧所",
			Content: "无！！！！",
		}
		c.JSON(200, map[string]interface{}{
			"name":    "zhangsan",
			"age":     21,
			"hobby":   []string{"唱歌", "跳舞"},
			"success": true,
			"article": article,
		})
	})

	r.GET("/jsonp", func(c *gin.Context) {
		article := &Article{
			Title:   "侧所",
			Content: "无！！！！",
		}
		c.JSONP(200, article)
	})

	r.GET("/xml", func(c *gin.Context) {
		c.XML(http.StatusOK, gin.H{
			"success": true,
			"msg":     "你好gin，我是一个xml",
		})
	})

	r.LoadHTMLGlob("../templates/*.html")
	r.GET("/html", func(c *gin.Context) {
		c.HTML(http.StatusOK, "goods.html", gin.H{
			"title":   "我是后台数据",
			"content": "我是内容哦～～",
		})
	})

	r.Run(":9000")

}
